package main.array;

import java.util.Arrays;
import java.util.HashSet;

/**
 * @author: kejl
 * @create: 2020-07-26 20:07
 */
public class ContainsDuplicate {
    public static void main(String[] args) {
        System.out.println(Integer.MAX_VALUE+5);
        System.out.println(Math.pow(2,31)+5);

//        int[] to = new int[]{0,0,1,1,1,2,2,3,3,4};
//        removeDuplicates(to);

int result = reverse(115647);




    }

    public static int reverse(int x) {
        int rev = 0;
        while (x != 0) {
            int pop = x % 10;
            x /= 10;
            if (rev > Integer.MAX_VALUE/10 || (rev == Integer.MAX_VALUE / 10 && pop > 7)) return 0;
            if (rev < Integer.MIN_VALUE/10 || (rev == Integer.MIN_VALUE / 10 && pop < -8)) return 0;
            rev = rev * 10 + pop;
        }
        return rev;
    }




    public static int removeDuplicates(int[] nums) {

        if(nums==null ){
            return 0;
        }
        if(nums.length ==1){
            return 1;
        }

        HashSet<Integer> numsSet = new HashSet<Integer>();

        int numsLength = nums.length;
        for(int i = 0;i<numsLength;i++){
            if(numsSet.contains(nums[i])){

                for(int j =i;j< numsLength;j++){

                    if(j+1 == nums.length){
                        nums[j] =0;
                    }else{
                        nums[j] = nums[j+1];
                    }


                }
                i--;
                numsLength--;
            }else{
                numsSet.add(nums[i]);

            }


        }
        return numsLength;
    }

}
